<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="org.apache.commons.lang.time.DateFormatUtils"%>
<%@page import="org.springframework.util.CollectionUtils"%>
<%@page import="cn.com.xf.common.Constants"%>
<%@page import="java.util.Collection"%>
<%@ include file="../common/common_include.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	List<TblDestination> list = (List<TblDestination>)request.getAttribute("list");
	DestinForm form = (DestinForm)request.getAttribute("command");
	String prov = StringUtils.isNotBlank(form.getProv())?form.getProv():"";
	String city = StringUtils.isNotBlank(form.getCity())?form.getCity():"";
	String area = StringUtils.isNotBlank(form.getArea())?form.getArea():"";
	String areaname = StringUtils.isNotBlank(form.getAreaname())?form.getAreaname():"";
	String address = StringUtils.isNotBlank(form.getAddress())?form.getAddress():"";
	UserInfo user = (UserInfo)SecurityContextHolder.getContext().getAuthentication().getPrincipal();	
	String userid = user.getName();
	String siteId = user.getSiteId();
	String auditor = user.getName();
%>

<div class="userListWrap" )>
    <form id="userListForm">
        <div class="form-item" style="width:140px">
    		<label for="userId">城市:</label>
    		<input class="easyui-validatebox" type="text" style="width:100px" name="city" data-options="" value="<%=city%>"/>
        </div>
       	<div class="form-item" style="width:140px">
    		<label for="userId">县/区:</label>
    		<input class="easyui-validatebox" type="text" style="width:100px" name="area" data-options="" value="<%=area%>"/>
        </div>
        <div class="form-item" style="width:140px">
    		<label for="userId">地址:</label>
    		<input class="easyui-validatebox" type="text" placeholder="不用再输入省市区" style="width:100px" name="address" data-options="" value="<%=address%>"/>
        </div>
       	<div class="form-item" style="width:140px">
    		<label for="userId">目的地:</label>
    		<input class="easyui-validatebox" type="text" style="width:100px" name="areaname" data-options="" value="<%=areaname%>"/>
        </div>
        <div class="form-item" style="width:200px">
        	<label for="userId"><input name="status" type="radio" value="" checked/>全部 </label> 
			<label for="userId"><input name="status" type="radio" value="0" />未审核</label> 
			<label for="userId"><input name="status" type="radio" value="1" />已审核</label> 
        </div>
        <input type="hidden" name="siteid" value="<%=siteId%>">
        <div class="form-item" style="width:80px">
        	<label for="deptId"></label>
    		<a href="javascript:XF.Destin.listDestinSearch()" class="input-btn-microsoft input-btn-microsoft-24">搜索</a>
        </div>
        
    </form>
    <table id="destinListTable" class="easyui-datagrid"  title="" >
        <thead>
    		<tr>
    			<th data-options="field:'id',hidden:'hidden'"></th>
    			<th data-options="field:'select',width:80,align:'center',checkbox:'ture'"><input type="checkbox" class="checkbox checkboxSelectAll"></th>    			
				<th data-options="field:'address',width:400">地址</th>				
				<th data-options="field:'areaname',width:80">目的地</th>				
				<th data-options="field:'userid',width:60">编辑人</th>
    			<th data-options="field:'updateTime',width:130">添加时间</th>
    			<th data-options="field:'opr',width:180">操作</th>					
				<th data-options="field:'auditor',width:60">审核人</th>
				<th data-options="field:'checkTime',width:130" >审核时间</th>				
				<th data-options="field:'memotext',width:140">备注</th>
	
      		</tr>
        </thead>
        <tbody>
        	<%
        		if(list!=null && list.size() > 0){
        			for(TblDestination destin:list){
        				%>
       					 <tr s="<%=destin.getId() %>">
       					 	<td hidden="hidden"><i s="<%=destin.getId() %>"></i><%=(null!=destin.getId())?destin.getId()+"":"" %></td>
       					 	<td></td>      					 	
       					 	<td><%=((null!=destin.getProv())?destin.getProv()+"":"")+((null!=destin.getCity())?destin.getCity()+"":"")+((null!=destin.getArea())?destin.getArea()+"":"")+((null!=destin.getAddress())?destin.getAddress()+"":"") %></td>       					 	
       					 	<td><%=(null!=destin.getAreaname())?destin.getAreaname()+"":"" %></td>
       					 	<td><%=(null!=destin.getUserid())?destin.getUserid()+"":"" %></td>
       					 	<td><%=null!=destin.getUpdateTime()?DateFormatUtils.format(destin.getUpdateTime().getTime(), "yyyy-MM-dd HH:mm:ss"):"" %></td>
       					 	<sec:authorize ifAnyGranted="MANAGE_DESTIN,AUDIT_DESTIN">
				    			<td>
				    				<sec:authorize ifAnyGranted="MANAGE_DESTIN">
										<a class="inLink" href="javascript:XF.Destin.editDestin('<%=destin.getId()+"" %>')"><span>编辑</span></a>
										<a class="inLink" href="javascript:XF.Destin.deleteDestin('<%=destin.getId()+"" %>',<%=siteId%>)"><span>删除</span></a>										
									</sec:authorize>
										<%if(destin.getStatus().equals("0")){%>
											<a class='auditTab' id="auditTab<%=destin.getId()+""%>">未审核</a>
										<%}else if(destin.getStatus().equals("1")){%>
											<a class='auditTab' id="auditTab<%=destin.getId()+""%>">已审核</a>
										<%}%>
									<sec:authorize ifAnyGranted="AUDIT_DESTIN">
										<%if(destin.getStatus().equals("0")){%>
											<a id="audit<%=destin.getId()+""%>" class="inLink"  href="javascript:XF.Destin.doAudit('<%=auditor %>','<%=destin.getId()+""%>')" class="a-btn-microsoft">审核</a>																			
										<%}else if(destin.getStatus().equals("1")){%>											
											<a id="audit<%=destin.getId()+""%>" class="inLink"  href="javascript:XF.Destin.doAudit('<%=auditor %>','<%=destin.getId()+""%>')" class="a-btn-microsoft">取消审核</a>
										<%}%>
									</sec:authorize>
				    			</td>
				    		</sec:authorize>
				    		<td><%=(null!=destin.getAuditor())?destin.getAuditor()+"":"" %></td>
       					 	<td><%=null!=destin.getCheckTime()?DateFormatUtils.format(destin.getCheckTime().getTime(), "yyyy-MM-dd HH:mm:ss"):"" %></td>
       					 	<td><%=(null!=destin.getMemotext())?destin.getMemotext()+"":"" %></td>
			    		</tr>
        				<%
        			}
        		}
        	%>
    	</tbody>
    </table>
    <div class="pagination paginationFixWidth">
		<monggoTag:pagination 
		href="destin_search"
		pageSize="<%=form.getPageSize()%>" 
		totalRecord="<%=form.getTotalRecord() %>" 
		currentPage="<%=form.getPageNum() %>">
		</monggoTag:pagination> 
	</div>
	<div>
		<input id="selectDel" class="input-btn-microsoft" type="button" value="批量删除">
		<input id="selectCancelAudit" class="input-btn-microsoft" type="button" value="批量取消审核">
		<input id="selectAudit" class="input-btn-microsoft" type="button" value="批量审核">
		<input id="allAudit" class="input-btn-microsoft" type="button" value="一键全审">
	</div>
</div>
<script>
	$('#destinListTable').datagrid();  
	$('#allAudit').click(function() {
		if(confirm("确认本站点未审核的地址全部都审核吗？")){
			XF.Destin.doAllAudit('<%=auditor %>','<%=siteId %>');
			XF.Destin.listDestin('<%=siteId%>');
		}
	});	
	$('#selectDel').click(function() {
		if(confirm("确认选中项都删除吗？")){
			var idArray = new Array();
			var audArray = new Array();
			$(".datagrid-btable tr").each(function() {
				var claval = $(this).attr('class');
				var aud = $(this).find('a.auditTab').html();
				if(claval.indexOf('checked')>=0){
					var id = $(this).children(":first").text();
					var audit = $(this).find('a.auditTab').html();
					audArray.push(audit);
					idArray.push(id);
				}
			});
			if(idArray.length >0){
				var idStr = JSON.stringify(idArray)
				var audStr = JSON.stringify(audArray);
				XF.Destin.doSelectDelete(idStr,audStr,'<%=siteId %>');
			}else{
				alert("没有选取记录！")
			}
		}
	});
	$('#selectCancelAudit').click(function() {
		if(confirm("确认选中项都取消审核吗？")){
			var idArray = new Array()
			$(".datagrid-btable tr").each(function() {
				var claval = $(this).attr('class');
				if(claval.indexOf('checked')>=0){
					var id = $(this).children(":first").text();
					idArray.push(id);
					$("#audit"+id+"" ).html("审核");
					$("#auditTab"+id+"" ).html("未审核");				
				}
			});
			if(idArray.length >0){
				var idStr = JSON.stringify(idArray)
				XF.Destin.doSelectCancelAudit('<%=auditor %>',idStr);
				$(".datagrid-btable tr").removeClass().addClass("datagrid-row");
				$(":checkbox").removeAttr("checked");
			}else{
				alert("没有选取记录！")
			}
		}
	});
	$('#selectAudit').click(function() {
		if(confirm("确认选中项都审核吗？")){
			var idArray = new Array()
			$(".datagrid-btable tr").each(function() {
				var claval = $(this).attr('class');
				if(claval.indexOf('checked')>=0){
					var id = $(this).children(":first").text();
					$("#audit"+id+"" ).html("取消审核");
					$("#auditTab"+id+"" ).html("已审核");
					idArray.push(id);
				}
			});
			if(idArray.length >0){
				var idStr = JSON.stringify(idArray)			
				XF.Destin.doSelectAudit('<%=auditor %>',idStr);
				$(".datagrid-btable tr").removeClass().addClass("datagrid-row");
				$(":checkbox").removeAttr("checked");
			}else{
				alert("没有选取记录！")
			}
		}
	});
	
</script>



